import java.util.*;

/**
 * @ClassName: LambdaDemo
 * @Author: liugui
 * @Date: 2021-08-03 14:31
 **/
public class LambdaDemo {
    public static void main(String[] args) {
        args = new String[]{"dddd", "a", "bb", "cc", "ddc"};
        List<String> words = Arrays.asList(args);
        System.out.println(words);
        // 匿名类
        Collections.sort(words,new Comparator<String>() {
                    @Override
                    public int compare(String o1, String o2) {
                        int compare = Integer.compare(o1.length(), o2.length());
                        return compare;
                    }
        });
        System.out.println(words);

        List<String> words2 = Arrays.asList("dddd", "a", "bb", "cc", "ddc");
        System.out.println(words2);
        // lambda 表达式
        Collections.sort(words2,((o1, o2) -> Integer.compare(o1.length(),o2.length())));
        System.out.println(words2);

        List<String> words3 = Arrays.asList("dddd", "a", "bb", "cc", "ddc");
        System.out.println(words3);
        // lambda 表达式 精简1
        Collections.sort(words3,(Comparator.comparingInt(String::length)));
        System.out.println(words3);

        List<String> words4 = Arrays.asList("dddd", "a", "bb", "cc", "ddc");
        System.out.println(words4);
        // lambda 表达式 精简2
        words4.sort(Comparator.comparingInt(String::length));
        System.out.println(words4);

    }
}
